public class Solution883 {
    public int projectionArea(int[][] grid) {
        int ans=0,n=grid.length;
        for (int i=0;i<n;i++){
            int max=grid[i][0];
            for (int j=0;j<n;j++){
                if (grid[i][j]>max){
                    max=grid[i][j];
                }
            }
            ans+=max;
        }
        for (int i=0;i<n;i++){
            int max=grid[0][i];
            for (int j=0;j<n;j++){
                if (grid[j][i]>max){
                    max=grid[j][i];
                }
            }
            ans+=max;
        }
        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++){
                if (grid[i][j]!=0){
                    ans++;
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution883().projectionArea(new int[][]{{1,2},{3,4}}));
    }
}
